package com.xuzao.developer.service.impl;

import com.github.pagehelper.PageInfo;
import com.xuzao.developer.base.model.GridFieldSys;
import com.xuzao.developer.base.model.GridTable;
import com.xuzao.developer.dao.GridFieldSysDao;
import com.xuzao.developer.dao.GridTableDao;
import com.xuzao.developer.dto.GridTableDTO;
import com.xuzao.developer.service.GridTableService;
import com.xuzao.developer.tools.entity.Pager;
import com.xuzao.developer.utils.LoginUserInfoUtil;
import com.xuzao.developer.vo.BaseResultVo;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;


/**
 * @author xuzao
 * @description
 * @date 2019-09-03 17:12:36
 **/
@Service("gridTableService")
public class GridTableServiceImpl implements GridTableService {

    @Resource
    private GridTableDao gridTableDao;
    @Resource
    private GridFieldSysDao gridFieldSysDao;

    @Override
    public PageInfo<GridTable> list(GridTableDTO dto, Pager pager) {
        return gridTableDao.list(dto, pager);
    }

    @Override
    public BaseResultVo insert(GridTableDTO dto) {
        GridTable gridTable = new GridTable();
        gridTable.setGridName(dto.getGridName());
        gridTable.setCreaterName(LoginUserInfoUtil.getLoginUser().getRealName());
        gridTable.setIsDeleted(0);
        Integer count = gridTableDao.insertSelective(gridTable);
        if (count > 0) {
            return BaseResultVo.success();
        }
        return BaseResultVo.error();

    }

    @Override
    public BaseResultVo update(GridTableDTO dto) {
        GridTable gridTable = new GridTable();
        gridTable.setGridName(dto.getGridName());
        gridTable.setId(dto.getId());
        Integer count = gridTableDao.updateSelectiveById(gridTable);
        if (count > 0) {
            return BaseResultVo.success();
        }
        return BaseResultVo.error();
    }

    @Override
    public GridTable get(GridTableDTO dto) {
        return gridTableDao.selectById(dto.getId());
    }

    @Override
    public void del(Long id) {

        GridTable gridTable = new GridTable();
        gridTable.setId(id);
        gridTable.setIsDeleted(1);
        gridTableDao.updateSelectiveById(gridTable);

    }
}